var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
    value: !0
});
var o = e("GIF"),
i = cc._decorator,
a = i.ccclass,
r = i.requireComponent,
s = function(e) {
    __extends(t, e);
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        t._path = "";
        t.sprite = null;
        t._index = 0;
        return t
    }
    Object.defineProperty(t.prototype, "path", {
        get: function() {
            return this._path
        },
        set: function(e) {
            if (null != e) {
                this._path = e;
                this.innerPath = e.toString();
                this.clear();
                this.applayChange()
            }
        },
        enumerable: !1,
        configurable: !0
    });
    t.prototype.setInnerPath = function(e) {
        this.innerPath = e;
        this.clear();
        this.applayChange()
    };
    t.prototype.onLoad = function() {
        this.sprite = this.node.getComponent(cc.Sprite);
        this.setInnerPath(this.path.toString())
    };
    t.prototype.setDefaultSpriteFrame = function(e) {
        this.sprite.spriteFrame = e
    };
    t.prototype.inited = function() {
        var e = this;
        this._index++;
        this._index >= this._spriteFrames.length && (this._index = 0);
        var t = this._spriteFrames[this._index];
        this.sprite.spriteFrame = t;
        var n = this._delays[this._index]; ! n || n < .01 ? n = .06 : n *= .01;
        this.scheduleOnce(function() {
            e.inited()
        },
        n)
    };
    t.prototype.getType = function() {
        var e = o.FileType.UNKNOWN;
        if (0 == this.innerPath.indexOf("/")) {
            var t = jsb.fileUtils.getDataFromFile(this.innerPath),
            n = o.GIF.bytes2HexString(t.slice(0, 50));
            e = o.GIF.detectFormat(n)
        }
        return e
    };
    t.prototype.applayChange = function() {
        var e = this,
        t = o.GIFCache.getInstance();
        if (this.innerPath) {
            var n = function(n, o) {
                if (n) cc.error("gif图片加载失败");
                else if (o instanceof cc.Texture2D) e.setDefaultSpriteFrame(new cc.SpriteFrame(o));
                else {
                    e._delays = o.delays;
                    e._spriteFrames = o.spriteFrames;
                    e._spriteFrames = o.spriteFrames;
                    e._positions = o.positions;
                    e.setDefaultSpriteFrame(o.spriteFrames[0]);
                    e.scheduleOnce(function() {
                        e.inited()
                    },
                    .1);
                    e._inited = !0;
                    t.addItemFrame(e.innerPath, o)
                }
            },
            i = o.FileType.UNKNOWN,
            a = t.get(this.innerPath);
            if (a) i = a.type;
            else {
                i = this.getType();
                t.addItemType(this.innerPath, i)
            }
            i == o.FileType.GIF ? t.hasFrame(this.innerPath) ? n(null, a.frameData) : cc.loader.load({
                url: this.innerPath,
                type: "gif"
            },
            n) : cc.loader.load(this.innerPath, n)
        }
    };
    t.prototype.clear = function() {
        this.unscheduleAllCallbacks();
        this._index = 0;
        this._inited = null;
        this._delays = null;
        this._spriteFrames = null
    };
    return __decorate([a, r(cc.Sprite)], t)
} (cc.Component);
n.default = s